package www.wmx.com.xssc.xm;

import www.wmx.com.xssc.xm.similarity.phrase.PhraseSimilarity;
import www.wmx.com.xssc.xm.similarity.sentence.editdistance.EditDistance;
import www.wmx.com.xssc.xm.similarity.sentence.editdistance.GregorEditDistanceSimilarity;
import www.wmx.com.xssc.xm.similarity.sentence.editdistance.NewEditDistanceSimilarity;
import www.wmx.com.xssc.xm.similarity.sentence.editdistance.StandardEditDistanceSimilarity;
import www.wmx.com.xssc.xm.similarity.sentence.morphology.MorphoSimilarity;
import www.wmx.com.xssc.xm.similarity.word.CharBasedSimilarity;
import www.wmx.com.xssc.xm.similarity.word.clin.CilinSimilarity;
import www.wmx.com.xssc.xm.similarity.word.hownet.concept.ConceptSimilarity;

import static www.wmx.com.xssc.util.similarity.ShinglingComparator.getJaccardSimilarity;

/**
 * Similarity 相似度计算工具包
 *
 * @author xuming
 */
public class Similarity {

    public static final class Config {
        /**
         * 词林编码路径
         */
        public static String CilinPath = "cilin.db.gz";
        /**
         * 拼音词典路径
         */
        public static String PinyinPath = "F02-GB2312-to-PuTongHua-PinYin.txt";
        /**
         * concept路径
         */
        public static String ConceptPath = "concept.dat";
        /**
         * concept.xml.gz路径
         */
        public static String ConceptXmlPath = "concept.xml.gz";
        /**
         * 义原关系的路径
         */
        public static String SememePath = "sememe.dat";
        /**
         * 义原数据路径
         */
        public static String SememeXmlPath = "sememe.xml.gz";
        /**
         * 词频统计输出路径
         */
        public static String StatisticsResultPath = "data/WordFrequencyStatistics-Result.txt";

    }

    public Similarity() {
    }


    /**
     * 词语相似度
     * 计算词林编码相似度
     *
     * @param word1 word
     * @param word2 word
     * @return float
     */
    public static double cilinSimilarity(String word1, String word2) {
        return CilinSimilarity.getInstance().getSimilarity(word1, word2);
    }

    /**
     * 词语相似度
     * 计算拼音相似度
     *
     * @param word1 word
     * @param word2 word
     * @return float
     */
    public static double pinyinSimilarity(String word1, String word2) {
        return PhraseSimilarity.getInstance().getSimilarity(word1, word2);
    }

    /**
     * 词语相似度
     * 计算字面相似度
     *
     * @param word1 word
     * @param word2 word
     * @return float
     */
    public static double charBasedSimilarity(String word1, String word2) {
        return CharBasedSimilarity.getInstance().getSimilarity(word1, word2);
    }

    /**
     * 词语相似度
     * 计算语义概念相似度
     *
     * @param word1
     * @param word2
     * @return
     */
    public static double conceptSimilarity(String word1, String word2) {
        return ConceptSimilarity.getInstance().getSimilarity(word1, word2);
    }

    /**
     * 短语相似度
     *
     * @param pharse1
     * @param pharse2
     * @return
     */
    public static double phraseSimilarity(String pharse1, String pharse2) {
        return PhraseSimilarity.getInstance().getSimilarity(pharse1, pharse2);
    }

    /**
     * 句子相似度
     * 词形和词序结合法
     *
     * @param sentence1
     * @param sentence2
     * @return
     */
    public static double morphoSimilarity(String sentence1, String sentence2) {
        return MorphoSimilarity.getInstance().getSimilarity(sentence1, sentence2);
    }

    /**
     * 句子相似度
     * 夏天编辑距离法
     *
     * @param sentence1
     * @param sentence2
     * @return
     */
    public static double editDistanceSimilarity(String sentence1, String sentence2) {
        EditDistance ed = new NewEditDistanceSimilarity();
        return ed.getSimilarity(sentence1, sentence2);
    }

    /**
     * 句子相似度
     * Gregor编辑距离算法
     *
     * @param sentence1
     * @param sentence2
     * @return
     */
    public static double gregorEditDistanceSimilarity(String sentence1, String sentence2) {
        EditDistance ed = new GregorEditDistanceSimilarity();
        return  ed.getSimilarity(sentence1, sentence2);
    }

    /**
     * 句子相似度
     * 标准编辑距离算法
     *
     * @param sentence1
     * @param sentence2
     * @return
     */


    public static double standardEditDistanceSimilarity(String sentence1, String sentence2) {
        EditDistance ed = new StandardEditDistanceSimilarity();
        return  ed.getSimilarity(sentence1, sentence2);
    }

    /**
     * 词语情感分析
     *
     * @param
     * @return
     */
/*    public static double tendency(String word) {
        HownetWordTendency hownetWordTendency = new HownetWordTendency();
        return hownetWordTendency.getTendency(word);
    }*/

    public static  void main(String args[]){
         String s1 = "低代码技术：该技术使用户不用代码操作也能实现前台的数据库搭建和表单生成，从而提高了工作效率，减轻了管理人员的工作负担。";

         String s2 = "低代码技术：该技术使用户不用代码操作也能实现前台的数据库搭建和表单生成，从而提高了工作效率，减轻了管理人员的工作负担。";

         String s3 = "低代码平台技术革新了软件开发模式，它赋予了非技术背景的用户以强大能力，无需编写传统代码即可构建前台数据库架构、自动生成表单，极大地提升了工作效率，有效减轻了管理人员在软件部署和维护上的负担。";

         String s4 = "低代码技术是一种革命性的工具，它显著改变了软件开发的传统模式。此技术允许用户在不编写任何代码的情况下，构建前台数据库架构和生成表单，极大地提升了工作效率，并有效减轻了管理人员的负担";

         String s5 = "流程引擎技术：该技术通过在前端建立符合业务流程建模标注标准的组件框架，使得用户可以通过可视化界面定义和修改新的流程。在后端低代码框架中实现流程引擎的支持后，可以根据前端构建的流程图进行后端部署，从而有效应对人员变动、流程优化等审批流程修改的需求，解决科研管理系统只有固定流程，遇到特殊情况只能在后端修改的局限性。";

         String s6 = "该技术，即低代码技术，通过与图形化界面的巧妙融合，极大地提升了操作的直观性与易理解性。用户无需编写任何代码，仅凭简单的拖拽、点击操作，即可实现对业务流程的高效管理。这一特性不仅促进了前台数据库构建与表单生成的便捷性，还显著提高了工作效率，有效缓解了管理人员的工作压力。";

         double similarity = getJaccardSimilarity(s1, s2);
         double similarity2 = getJaccardSimilarity(s1, s3);
         double similarity3 = getJaccardSimilarity(s1, s4);
         double similarity4 = getJaccardSimilarity(s1, s5);
         double similarity5 = getJaccardSimilarity(s2, s3);
         double similarity6 = getJaccardSimilarity(s1, s6);
         double similarity7 = getJaccardSimilarity(s3, s6);

        System.out.println(similarity);
        System.out.println(similarity2);
        System.out.println(similarity3);
        System.out.println(similarity4);
        System.out.println(similarity5);
        System.out.println(similarity6);
        System.out.println(similarity7);
    }

}

